package com.xie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xie.domain.Result;
import com.xie.pojo.Medicine;
import com.xie.pojo.Paitient;
import com.xie.pojo.Personnel;
import com.xie.pojo.Vo.PaitientVo;
import com.xie.service.PaitientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "病人管理")
@RestController
@RequestMapping("/Paitients")
public class PaitientController {
    @Autowired
    private PaitientService paitientService;

    /**
     * 分页查询
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @ApiOperation("获取分页病人数据")
    @GetMapping("{pageIndex}/{pageSize}")
    public Result findPaitient(@PathVariable Integer pageIndex, @PathVariable Integer pageSize){
        Page page=new Page(pageIndex,pageSize);
        Page page1 = paitientService.page(page);
        if (page1 != null) return Result.ok(page1);
        return Result.fail();
    }

    /**
     * 模糊查询病人
     * @param params
     * @return
     */
    @GetMapping("find/{params}")
    @ApiOperation("模糊查询病人信息")
    public Result FindPage(@PathVariable String params){
        LambdaQueryWrapper<Paitient> lambdaQueryWrapper=new LambdaQueryWrapper();
        lambdaQueryWrapper.like(Paitient::getPaitientId,params)
                .or().like(Paitient::getPaitientBed,params)
                .or().like(Paitient::getPaitientDateStart,params)
                .or().like(Paitient::getPaitientDept,params)
                .or().like(Paitient::getPaitientDoc,params)
                .or().like(Paitient::getPaitientGender,params)
                .or().like(Paitient::getPaitientName,params)
                .or().like(Paitient::getPaitientRoom,params)
                .or().like(Paitient::getPaitientState,params)
                .or().like(Paitient::getStatus,params)
        ;
        List<Paitient> list = paitientService.list(lambdaQueryWrapper);
        if (list != null) return Result.ok(list);
        return Result.fail();
    }

    /**
     * 添加病人
     * @param paitient
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("添加病人数据")
    public Result addPaitient(@RequestBody Paitient paitient) {
        boolean save = paitientService.save(paitient);
        if (save) return Result.ok();
        return Result.fail();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/removeById/{id}")
    @ApiOperation("根据id删除病人信息")
    public Result deletePaitient(@PathVariable Integer id) {
        boolean b = paitientService.removeById(id);
        if (b) return Result.ok();
        return Result.fail();
    }


    /**
     * 修改
     * @param paitient
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改病人数据")
    public Result updatePaitient(@RequestBody Paitient paitient) {
        boolean update = paitientService.updateById(paitient);
        if (update) return Result.ok();
        return Result.fail();

    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据id查询病人信息")
    public Result findPaitientById(@PathVariable Integer id){
        Paitient pa2= paitientService.getById(id);
        if (pa2 != null) return Result.ok(pa2);
        return Result.fail();
    }


    /**
     * 获取全部
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("获取所有的病人信息")
    public Result exportPotion(){
        List<Paitient> paitients = paitientService.list();
        if (paitients != null)return Result.ok(paitients);
        return Result.fail();
        }


    /**
     * 链表查询
     * @return
     */
    @GetMapping("/findPePa")
    @ApiOperation("联表查询员工所管理病人的信息")
    public Result findPP() {
        List<PaitientVo> pp = paitientService.findPP();
        if (pp != null) {
            return Result.ok(pp);
        }
        return Result.fail();
        }
    }


